#include "animal.h"
#include <stdlib.h>

Square::Square(unsigned int x, unsigned int y) : X(x), Y(y)
{
}

Animal::Animal(Square maxsqr)
{
    CurrentSquare.X = maxsqr.X;
    CurrentSquare.Y = maxsqr.Y;
}

void Animal::StepToNextSquare()
{
    bool CanMoveToLeft = true;
    bool CanMoveToRight = true;
    bool CanMoveToUp = true;
    bool CanMoveToDown = true;

    if(CurrentSquare.X == 0) CanMoveToLeft = false;
    if(CurrentSquare.X == MaxSquare.X) CanMoveToRight = false;
    if(CurrentSquare.Y == 0) CanMoveToUp = false;
    if(CurrentSquare.Y == MaxSquare.Y) CanMoveToDown = false;


    int dx_range = (!CanMoveToLeft || !CanMoveToRight) ? 2 : 3;
    int dy_range = (!CanMoveToUp || !CanMoveToDown) ? 2 : 3;
    int dx = (rand() % dx_range) - 1; if(!CanMoveToLeft) dx ++;
    int dy = (rand() % dy_range) - 1; if(!CanMoveToUp) dy ++;
    CurrentSquare.X += dx;
    CurrentSquare.Y += dy;
}
